/**
 * @(#)Test.java, Nov 21, 2012. 
 * 
 * Copyright 2012 Yodao, Inc. All rights reserved.
 * YODAO PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.buaaer.net;

import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 *
 * @author wangheng
 *
 */
public class Test {


    public static void main(String[] args) throws Exception {

        ServerSocket server = new ServerSocket(9876);
        
        Socket socket = server.accept();
        
        OutputStream output = socket.getOutputStream();
        
        while (true) {
            generator(output);
        } 
    }
    
    public static void generator(OutputStream output) throws Exception {
        
        int firstPrintableCharacter = 33;
        int numberOfPrintableCharacters = 94;
        int start = firstPrintableCharacter;
        
        byte[] buf = new byte[74];
        
        while (true) {
            for ( int i = start; i < start+71; i++) {
                buf[i - start] = (byte)((i - firstPrintableCharacter) & numberOfPrintableCharacters + firstPrintableCharacter);
            }
            buf[72] = '\r';
            buf[73] = '\n';
            start = ((start + 1) - firstPrintableCharacter) % numberOfPrintableCharacters + firstPrintableCharacter;
            output.write(buf);
        }
        
        
    }

}

